using UnityEngine;
using System.Collections;

/**
 * Script of curor display.
 * The purpose of this class is to display mouse cursor.
 * @author Benjamin Bruneau
 */
public class MouseCursorScript : MonoBehaviour 
{
	
	private const string PAUSE_MANAGER_NAME = "PauseManager";
	
	public Texture _cursorTexture;
	
	/**
	 * Called on initialization.
	 * @return void
	 */
	void Start () 
	{
		// Don't destroy and hide system cursor
		DontDestroyOnLoad(this);
		Screen.showCursor = false;
		
	}
	
	/**
	 * Called on GUI.
	 * @return void
	 */
	void OnGUI () 
	{
	
		// Live finding because this game object moves through scenes
		if(!GameObject.Find (PAUSE_MANAGER_NAME))
		{		
			displayCursor();
			
		} else {
			if(GameObject.Find (PAUSE_MANAGER_NAME).GetComponent<PauseControllerScript>()._pause)
			{
				displayCursor();
			}
		}
	}
	
	/**
	 * Displays mouse cursor.
	 * @return void
	 */
	private void displayCursor()
	{
		Vector3 mousePositon = Input.mousePosition;
		Rect position = new Rect(mousePositon.x,Screen.height - mousePositon.y,_cursorTexture.width,_cursorTexture.height);
		GUI.Label(position, _cursorTexture);
	}
}
